package com.oyz;

import java.util.Random;

/**
 * 生产者线程
 */
public class ProducerThread extends Thread {
    private final MyQueue myQueue;
    private final Random random = new Random();
    public ProducerThread(MyQueue myQueue) {
        this.myQueue = myQueue;
    }
    // 记录下标
    private int index = 0;


    @Override
    public void run() {
        String str = "生产数据:"+index;
        while(true){
            myQueue.put(str);
            System.out.println(str);
            ++index;
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
      }
}
